package cn.wolfcode.mp.web.controller;


import cn.wolfcode.mp.anno.RequiredPermission;
import cn.wolfcode.mp.domain.Permission;
import cn.wolfcode.mp.query.JsonResult;
import cn.wolfcode.mp.query.PermissionQuery;
import cn.wolfcode.mp.service.IPermissionService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("permission")
public class PermissionController {

    @Autowired
    private IPermissionService permissionService;

    // 处理查询所有角色请求
    // /permission/list 目前不带参数,响应HTML 格式内容
    @RequiredPermission(name = "权限页面", expression = "permission:list")
    @RequestMapping("/list")
    public String list(Model model,  @ModelAttribute("qo") PermissionQuery qo) {
        //获取所有 部门数据,存到Model 中
        IPage<Permission> page = permissionService.queryPage(qo);
        model.addAttribute("page", page);
        return "permission/list"; //WEB-INF/views/permission/list.jsp
    }

    @RequiredPermission(name = "权限加载", expression = "permission:reload")
    @ResponseBody
    @RequestMapping("/reload")
    public JsonResult reload() {
        permissionService.reload();
        return new JsonResult();
    }
}
